
import java.io.PrintWriter;
import java.util.HashMap;

class Expr extends Node {

	private int operator;
	private boolean unary = false;
	private Node atom;
	private Node left = null;
	private Node right = null;

	// Unary operations
	public Expr(int pOperator, Node pAtom) {
		operator = pOperator;
		atom = pAtom;
		unary = true;

	}

	// Binary operations
	public Expr(int pOperator, Node pLeft, Node pRight) {
		operator = pOperator;
		left = pLeft;
		right = pRight;
	}

	@Override
	public void print(PrintWriter pw) {
		pw.println("Node name : Expr");
		// assert(op_);
		if (unary) {
			pw.println("Unary op is : " + operator);
			// assert(atom_);
			atom.print(pw);
		} else {
			pw.println("Binary op is : " + operator);
			// assert(left_ && right_);
			left.print(pw);
			right.print(pw);
		}
	}
	
	public String translate(HashMap<String, PrintWriter> pws, String strPare, SymbolTable rt, String parent) {
		String key = rt.getStack().get(1);
		PrintWriter pw = pws.get(key);
		
		left.translate(pws,null, rt, parent);
		switch(operator){
			case sym.OR : 
				pw.print("||");
				break;
			case sym.AND : 
				pw.print("&&");
				break;
			case sym.LESS :
				pw.print("<");
				break;
			case sym.LESS_EQUAL :
				pw.print("<=");
				break;
			case sym.EQUAL :
				pw.print("==");
			        break;
			case sym.NOT_EQUAL :
				pw.print("!=");
				break;
			case sym.GREATER :	
				pw.print(">");
				break;
			case sym.GREATER_EQUAL:
				pw.print(">=");
				break;
			case sym.PLUS:
				pw.print("+");
				break;
			case sym.MINUS:	
				pw.print("-");
				break;
			case sym.TIMES:
				pw.print("*");
				break;
			case sym.DIVIDE:
				pw.print("/");
				break;
			case sym.MOD:
				pw.print("%");
				break;
		}
		right.translate(pws, null, rt, parent);		
		return null;
	}

}
